package my.diplom.web.validators;

import org.springframework.validation.Validator;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.apache.log4j.Logger;
import my.diplom.entity.Category;
import my.diplom.entity.Project;

/**
 * Created by IntelliJ IDEA.
 * User: gb
 * Date: 05.08.2009
 * Time: 0:01:49
 * To change this template use File | Settings | File Templates.
 */
public class CreateProjectValidator implements Validator {


     private static final Logger log = Logger.getLogger(CreateProjectValidator.class);

     public boolean supports(Class clazz) {
        return Project.class.equals(clazz);
    }

     @Override
    public void validate(Object o, Errors errors) {
        log.debug("validate project" + o);
        Project project = (Project) o;
        if (project == null) errors.reject("Null data received");

        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "projectName", "projectName.empty", "project Name is required");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "status", "status.empty", "status is required");



    }
}
